﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
namespace Manage_Pupils
{
    public partial class FormTimKiem : Form
    {
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.buttonThoat = new System.Windows.Forms.Button();
            this.textTenHS = new System.Windows.Forms.TextBox();
            this.buttonTimkiem = new System.Windows.Forms.Button();
            this.textMaHS = new System.Windows.Forms.TextBox();
            this.grvHS = new System.Windows.Forms.DataGridView();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.textHoHS = new System.Windows.Forms.TextBox();
            this.lb_hoHs = new System.Windows.Forms.Label();
            this.textNamHoc = new System.Windows.Forms.TextBox();
            this.lb_namhoc = new System.Windows.Forms.Label();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.textTenKhoi = new System.Windows.Forms.TextBox();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.lb_tenkhoi = new System.Windows.Forms.Label();
            this.lb_tenlop = new System.Windows.Forms.Label();
            this.textTenLop = new System.Windows.Forms.TextBox();
            this.lb_hocsinh = new System.Windows.Forms.Label();
            this.lb_maHS = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.grvHS)).BeginInit();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.BackColor = System.Drawing.Color.Transparent;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))));
            this.label1.Location = new System.Drawing.Point(290, 34);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(324, 24);
            this.label1.TabIndex = 25;
            this.label1.Text = "TÌM KIẾM THÔNG TIN HỌC SINH";
            // 
            // buttonThoat
            // 
            this.buttonThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.buttonThoat.Location = new System.Drawing.Point(221, 384);
            this.buttonThoat.Name = "buttonThoat";
            this.buttonThoat.Size = new System.Drawing.Size(129, 27);
            this.buttonThoat.TabIndex = 32;
            this.buttonThoat.Text = "Thoát";
            this.buttonThoat.UseVisualStyleBackColor = true;
            this.buttonThoat.Click += new System.EventHandler(this.buttonThoat_Click);
            // 
            // textTenHS
            // 
            this.textTenHS.Location = new System.Drawing.Point(166, 231);
            this.textTenHS.Name = "textTenHS";
            this.textTenHS.Size = new System.Drawing.Size(184, 21);
            this.textTenHS.TabIndex = 9;
            // 
            // buttonTimkiem
            // 
            this.buttonTimkiem.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.buttonTimkiem.Location = new System.Drawing.Point(62, 384);
            this.buttonTimkiem.Name = "buttonTimkiem";
            this.buttonTimkiem.Size = new System.Drawing.Size(124, 27);
            this.buttonTimkiem.TabIndex = 28;
            this.buttonTimkiem.Text = "Tìm kiếm";
            this.buttonTimkiem.UseVisualStyleBackColor = true;
            this.buttonTimkiem.Click += new System.EventHandler(this.buttonThem_Click_1);
            // 
            // textMaHS
            // 
            this.textMaHS.Location = new System.Drawing.Point(166, 155);
            this.textMaHS.Name = "textMaHS";
            this.textMaHS.Size = new System.Drawing.Size(184, 21);
            this.textMaHS.TabIndex = 7;
            // 
            // grvHS
            // 
            this.grvHS.BackgroundColor = System.Drawing.Color.OliveDrab;
            this.grvHS.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grvHS.Location = new System.Drawing.Point(441, 81);
            this.grvHS.Name = "grvHS";
            this.grvHS.Size = new System.Drawing.Size(606, 421);
            this.grvHS.TabIndex = 27;
            // 
            // groupBox1
            // 
            this.groupBox1.BackColor = System.Drawing.Color.Transparent;
            this.groupBox1.Controls.Add(this.textHoHS);
            this.groupBox1.Controls.Add(this.lb_hoHs);
            this.groupBox1.Controls.Add(this.textNamHoc);
            this.groupBox1.Controls.Add(this.lb_namhoc);
            this.groupBox1.Controls.Add(this.radioButton1);
            this.groupBox1.Controls.Add(this.radioButton3);
            this.groupBox1.Controls.Add(this.textTenKhoi);
            this.groupBox1.Controls.Add(this.radioButton2);
            this.groupBox1.Controls.Add(this.lb_tenkhoi);
            this.groupBox1.Controls.Add(this.buttonThoat);
            this.groupBox1.Controls.Add(this.lb_tenlop);
            this.groupBox1.Controls.Add(this.textTenLop);
            this.groupBox1.Controls.Add(this.textTenHS);
            this.groupBox1.Controls.Add(this.textMaHS);
            this.groupBox1.Controls.Add(this.lb_hocsinh);
            this.groupBox1.Controls.Add(this.buttonTimkiem);
            this.groupBox1.Controls.Add(this.lb_maHS);
            this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.groupBox1.Location = new System.Drawing.Point(17, 74);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(401, 428);
            this.groupBox1.TabIndex = 26;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Thông tin chi tiết về học sinh";
            // 
            // textHoHS
            // 
            this.textHoHS.Location = new System.Drawing.Point(166, 194);
            this.textHoHS.Name = "textHoHS";
            this.textHoHS.Size = new System.Drawing.Size(184, 21);
            this.textHoHS.TabIndex = 42;
            // 
            // lb_hoHs
            // 
            this.lb_hoHs.AutoSize = true;
            this.lb_hoHs.Location = new System.Drawing.Point(60, 200);
            this.lb_hoHs.Name = "lb_hoHs";
            this.lb_hoHs.Size = new System.Drawing.Size(83, 15);
            this.lb_hoHs.TabIndex = 41;
            this.lb_hoHs.Text = "Họ học sinh";
            // 
            // textNamHoc
            // 
            this.textNamHoc.Location = new System.Drawing.Point(166, 269);
            this.textNamHoc.Name = "textNamHoc";
            this.textNamHoc.Size = new System.Drawing.Size(184, 21);
            this.textNamHoc.TabIndex = 40;
            // 
            // lb_namhoc
            // 
            this.lb_namhoc.AutoSize = true;
            this.lb_namhoc.Location = new System.Drawing.Point(63, 275);
            this.lb_namhoc.Name = "lb_namhoc";
            this.lb_namhoc.Size = new System.Drawing.Size(64, 15);
            this.lb_namhoc.TabIndex = 39;
            this.lb_namhoc.Text = "Năm học";
            // 
            // radioButton1
            // 
            this.radioButton1.AutoSize = true;
            this.radioButton1.Checked = true;
            this.radioButton1.Location = new System.Drawing.Point(62, 20);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new System.Drawing.Size(198, 19);
            this.radioButton1.TabIndex = 33;
            this.radioButton1.TabStop = true;
            this.radioButton1.Text = "Tìm kiếm trong toàn trường";
            this.radioButton1.UseVisualStyleBackColor = true;
            this.radioButton1.CheckedChanged += new System.EventHandler(this.Choice_Checked);
            // 
            // radioButton3
            // 
            this.radioButton3.AutoSize = true;
            this.radioButton3.Location = new System.Drawing.Point(62, 100);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.Size = new System.Drawing.Size(145, 19);
            this.radioButton3.TabIndex = 30;
            this.radioButton3.Text = "Tìm kiếm trong lớp";
            this.radioButton3.UseVisualStyleBackColor = true;
            this.radioButton3.CheckedChanged += new System.EventHandler(this.Choice_Checked);
            // 
            // textTenKhoi
            // 
            this.textTenKhoi.Enabled = false;
            this.textTenKhoi.Location = new System.Drawing.Point(166, 309);
            this.textTenKhoi.Name = "textTenKhoi";
            this.textTenKhoi.Size = new System.Drawing.Size(184, 21);
            this.textTenKhoi.TabIndex = 38;
            // 
            // radioButton2
            // 
            this.radioButton2.AutoSize = true;
            this.radioButton2.Location = new System.Drawing.Point(62, 56);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new System.Drawing.Size(152, 19);
            this.radioButton2.TabIndex = 29;
            this.radioButton2.Text = "Tìm kiếm trong khối";
            this.radioButton2.UseVisualStyleBackColor = true;
            this.radioButton2.CheckedChanged += new System.EventHandler(this.Choice_Checked);
            // 
            // lb_tenkhoi
            // 
            this.lb_tenkhoi.AutoSize = true;
            this.lb_tenkhoi.Enabled = false;
            this.lb_tenkhoi.Location = new System.Drawing.Point(65, 315);
            this.lb_tenkhoi.Name = "lb_tenkhoi";
            this.lb_tenkhoi.Size = new System.Drawing.Size(62, 15);
            this.lb_tenkhoi.TabIndex = 37;
            this.lb_tenkhoi.Text = "Tên khối";
            // 
            // lb_tenlop
            // 
            this.lb_tenlop.AutoSize = true;
            this.lb_tenlop.Enabled = false;
            this.lb_tenlop.Location = new System.Drawing.Point(63, 351);
            this.lb_tenlop.Name = "lb_tenlop";
            this.lb_tenlop.Size = new System.Drawing.Size(55, 15);
            this.lb_tenlop.TabIndex = 32;
            this.lb_tenlop.Text = "Tên lớp";
            // 
            // textTenLop
            // 
            this.textTenLop.Enabled = false;
            this.textTenLop.Location = new System.Drawing.Point(166, 345);
            this.textTenLop.Name = "textTenLop";
            this.textTenLop.Size = new System.Drawing.Size(184, 21);
            this.textTenLop.TabIndex = 31;
            // 
            // lb_hocsinh
            // 
            this.lb_hocsinh.AutoSize = true;
            this.lb_hocsinh.Location = new System.Drawing.Point(60, 237);
            this.lb_hocsinh.Name = "lb_hocsinh";
            this.lb_hocsinh.Size = new System.Drawing.Size(89, 15);
            this.lb_hocsinh.TabIndex = 2;
            this.lb_hocsinh.Text = "Tên học sinh";
            // 
            // lb_maHS
            // 
            this.lb_maHS.AutoSize = true;
            this.lb_maHS.Location = new System.Drawing.Point(60, 161);
            this.lb_maHS.Name = "lb_maHS";
            this.lb_maHS.Size = new System.Drawing.Size(85, 15);
            this.lb_maHS.TabIndex = 0;
            this.lb_maHS.Text = "Mã học sinh";
            // 
            // FormTimKiem
            // 
            this.BackgroundImage = global::Manage_Pupils.Properties.Resources.hinhnen;
            this.ClientSize = new System.Drawing.Size(1065, 514);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.grvHS);
            this.Controls.Add(this.groupBox1);
            this.Name = "FormTimKiem";
            this.Text = "Tìm kiếm thông tin học sinh";
            this.Load += new System.EventHandler(this.FormCapNhatHS_Load_1);
            ((System.ComponentModel.ISupportInitialize)(this.grvHS)).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void buttonThem_Click_1(object sender, EventArgs e)
        {
            connect();
            SqlCommand command = new SqlCommand();
             command.Connection = con;                             //Ket noi
            //Xac dinh loai cau lenh can lay du lieu,Text: cau lenh SQL(ngam dinh)
            command.CommandType = CommandType.Text;

            if (radioButton1.Checked == true)
            {

                command.CommandText = @"Select HocSinh.MaHS, HocSinh.HoHS, HocSinh.TenHS, HocSinh.NgaySinh, HocSinh.DiaChi,HocSinh.GioiTinh,HocSinh.DienThoai,Lop.TenLop,Lop.NamHoc from HocSinh,Lop WHERE HocSinh.MaLop = Lop.MaLop" +
                                                                        " and MaHS LIKE " + "'" + textMaHS.Text + "%" + "'" +
                                                                         " and HoHS LIKE " + "'" + textHoHS.Text + "%" + "'" +
                                                                          " and NamHoc LIKE " + "'" + textNamHoc.Text + "%" + "'" +
                                                                        " and TenHS like "+"'"+textTenHS.Text+"%" +"'";

            }
            else if (radioButton2.Checked ==true)
            {
                command.CommandText = @"Select HocSinh.MaHS, HocSinh.HoHS, HocSinh.TenHS, HocSinh.NgaySinh, HocSinh.DiaChi,HocSinh.GioiTinh,HocSinh.DienThoai,Lop.TenLop,Lop.NamHoc from HocSinh,Lop, Khoi WHERE HocSinh.MaLop = Lop.MaLop" +
                                                                        " and Khoi.MaKhoi =Lop.MaKhoi" +
                                                                        " and MaHS    LIKE " + "'" + textMaHS.Text +    "%" + "'" +
                                                                         " and HoHS LIKE " + "'" + textHoHS.Text + "%" + "'" +
                                                                          " and NamHoc LIKE " + "'" + textNamHoc.Text + "%" + "'" +
                                                                        " and TenHS   like " + "'" + textTenHS.Text +   "%" + "'" +
                                                                        " and TenKhoi like " + "'" + textTenKhoi.Text + "%" + "'";
                                                                             

            }
            else if (radioButton3.Checked == true) 
            {
                command.CommandText = @"Select HocSinh.MaHS, HocSinh.HoHS, HocSinh.TenHS, HocSinh.NgaySinh, HocSinh.DiaChi,HocSinh.GioiTinh,HocSinh.DienThoai,Lop.TenLop,Lop.NamHoc from HocSinh,Lop WHERE HocSinh.MaLop = Lop.MaLop" +
                                                                         " and MaHS    LIKE " + "'" + textMaHS.Text + "%" + "'" +
                                                                          " and HoHS LIKE " + "'" + textHoHS.Text + "%" + "'" +
                                                                          " and NamHoc LIKE " + "'" + textNamHoc.Text + "%" + "'" +
                                                                         " and TenHS   like " + "'" + textTenHS.Text + "%" + "'"+
                                                                          " and TenLop like " + "'" + textTenLop.Text + "%" + "'";       
            }

            daHS.SelectCommand = command;//Gan command cho da
           if(daHS!=null) dtHS.Clear();
            daHS.Fill(dtHS);//Nap du lieu cho table
            grvHS.DataSource = dtHS;//Load du lieu len DataGriview
        }

        private void Choice_Checked(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {

                textTenKhoi.Enabled = false;
                lb_tenkhoi.Enabled = false;
                textTenLop.Enabled = false;
                lb_tenlop.Enabled = false;
            }
             else if (radioButton2.Checked == true)
            {


                textTenKhoi.Enabled = true;
                lb_tenkhoi.Enabled = true;
                textTenLop.Enabled = false;
                lb_tenlop.Enabled = false;
            }
            else
            {

                textTenKhoi.Enabled = false;
                lb_tenkhoi.Enabled = false;
                textTenLop.Enabled = true;
                lb_tenlop.Enabled = true;
            }

        }

        private void FormCapNhatHS_Load_1(object sender, EventArgs e)
        {

        }
        
        private void buttonThoat_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }
         
    }
}
